// 创建APP
const express = require('express');
const app = express();
const expressWs = require('express-ws');
expressWs(app);

// 配置cookie
const cookieParser = require('cookie-parser');
app.use(cookieParser());


// 允许访问图片目录
// app.get('/uploads/*', function (req, res) {
//     res.sendFile( __dirname + "/" + req.url );
// });

// 引入全局变量
require('./common/global');

// 注册广播对象
global.aWss = expressWs(app).getWss();

// 生成公钥、私钥，用于cookie加密
const RSA = require('./common/RSAClass');
new RSA().creatToken();


const WSAPIPATH = './router/api-ws/socket';
app.use('/api/role', require(WSAPIPATH + '/birth'));
app.use('/api/role', require(WSAPIPATH + '/offline'));

// 监听端口
app.listen('4444',()=>{
    console.log('websocket server success! path: 4444')
});

module.exports = app;